package org.example.smartbuy.controller;

import org.example.smartbuy.Result;
import org.example.smartbuy.entity.Inventory;
import org.example.smartbuy.service.IInventoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/inventory")
@Tag(name = "Inventory操作", description = "Operations related to inventory")
public class InventoryController {

    @Autowired
    private IInventoryService inventoryService;

    /**
     * 获取所有库存信息
     * @return List<Inventory>
     */
    @GetMapping("/list")
    @Operation(summary = "Get all inventory records", description = "Fetch a list of all inventory records",
            responses = {
                    @ApiResponse(responseCode = "200", description = "操作成功"),
                    @ApiResponse(responseCode = "400", description = "操作失败")
            })
    public Result listAllInventory() {
        return Result.success(inventoryService.listAll());
    }


    /**
     * 更新库存信息
     * @param inventory 更新的库存信息
     * @return Inventory
     */
    @PutMapping("/update")
    @Operation(summary = "Update an inventory record", description = "Update an existing inventory record",
            responses = {
                    @ApiResponse(responseCode = "200", description = "操作成功"),
                    @ApiResponse(responseCode = "400", description = "操作失败")
            })
    public Result updateInventory(@RequestBody Inventory inventory, int adminId) {
        return Result.success(inventoryService.update(inventory, adminId));
    }
}
